﻿using System.Linq;
using Basmus.Conel;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace Basmus.Tests
{
    [TestClass()]
    public class StringBindingTest
    {

        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod()]
        public void StringBindingConstructorTest()
        {
            var target = new StringBinding();
            Assert.IsTrue(target.ElementType == typeof(string));
            
        }

        [TestMethod()]
        public void GetContainerTest()
        {
            //Arrange & Act & Assert
            var target = new StringBinding();
            var elementsCollection = ElementsHelper.GetElementsOf<string>();
            foreach (var elements in elementsCollection)
            {
                var arg = elements == null ? null : elements.Cast<object>().ToArray();
                //Arrange
                var expectedContainer = elements == null
                                            ? null
                                            : (!elements.Any() ? string.Empty : (elements.ElementAt(0)) ?? string.Empty);

                //Act
                var actualConatainer = (string) target.GetContainer(arg);

                //Assert
                Assert.AreEqual(expectedContainer, actualConatainer);
            }
        }

        [TestMethod()]
        public void GetElementsTest()
        {
            var target = new StringBinding();
            var entityCollection = ContainerHelper.GetContainersOfEntity<string>();
            foreach (var container in entityCollection)
            {
                var expectedElements = container == null
                                           ? null
                                           : (container == string.Empty
                                                  ? new string[0]
                                                  : new[] {container});
                

                //Act
                var actualElements = target.GetElements(container);

                //Assert
                CollectionAssertHelper.AreEqual(expectedElements, actualElements);
            }
        }
    }
}
